package aliyun.cx.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import aliyun.cx.admin.entity.RolePermission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface RolePermissionMapper extends BaseMapper<RolePermission> {
    
    /**
     * 根据角色ID查询权限名称列表
     */
    @Select("SELECT p.name FROM permission p " +
            "INNER JOIN role_permission rp ON p.id = rp.permission_id " +
            "WHERE rp.role_id = #{roleId}")
    List<String> getPermissionNamesByRoleId(Long roleId);
    
    /**
     * 根据用户ID查询权限名称列表（通过用户角色关联）
     */
    @Select("SELECT DISTINCT p.name FROM permission p " +
            "INNER JOIN role_permission rp ON p.id = rp.permission_id " +
            "INNER JOIN user_roles ur ON rp.role_id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<String> getPermissionNamesByUserId(Long userId);
}
